﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Collections.ObjectModel;

namespace Nav
{
    /// 
    /// <summary>
    /// This is container for menu items. we have 2 of them in Navigation menu: active and 
    /// inactive</summary>
    /// 
    [TemplatePart(Name = NavigationMenuBand.TP_ITEMS_PART, Type = typeof(ItemsControl))]
    public class NavigationMenuBand : Control
    {
        public const string                         TP_ITEMS_PART = "itemControl";

        public List<Node>                           m_items;
        public ItemsControl                         m_itemControl;

        public NavigationMenuBand()
        {
            this.DefaultStyleKey = typeof(NavigationMenuBand);
        }

        /// 
        /// <summary>
        /// Parent NavigationMenu resets value of this property when we navigate back or
        /// forward in menu</summary>
        /// 
        public List<Node> ItemList
        {
            get
            {
                return m_items;
            }
            set
            {
                m_items = value;

                if (m_itemControl != null)
                {
                    m_itemControl.ItemsSource = m_items;
                }
            }
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            m_itemControl = (ItemsControl) GetTemplateChild(TP_ITEMS_PART);
            Debug.Assert(m_itemControl != null);

            m_itemControl.Items.Clear();

            if (m_itemControl != null)
            {
                m_itemControl.ItemsSource = m_items;
            }
        }
    }
}
